<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('图片专辑列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId">
            <div class="form-inline">
                <a class="btn btn-success mr-1" id="btn-add">
                    <i class="fa fa-upload"></i> 添加专辑
                </a>
                <input type="text" class="form-control mr-1" name="searchKey" placeholder="请输入标题或id...">
                <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                    <i class="fa fa-search"></i>
                    搜索
                </button>
                <button type="button" class="btn btn-default" onclick="$.form.reset()">
                    <i class="fa fa-refresh"></i>
                    重置
                </button>
                <input type="hidden" name="channelId" th:value="${channelId}"/>
            </div>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var prefix = "/picture/album";
    var channelId = [[${channelId}]];

    $(function() {
        var options = {
            url: prefix + "/list.json",
            updateUrl: prefix + "/edit.html?id={id}",
            modalName: "专辑",
            columns: [
                {
                    field: 'id',
                    title: 'id',
                    width: 80
                },
                {
                    field: 'title',
                    title: '专辑名称'
                },
                {
                    field: 'categoryName',
                    title: '类别',
                    width: 120
                },
                {
                    field: 'viewCount',
                    align: 'center',
                    title: '浏览数',
                    width: 80
                },
                {
                    field: 'status',
                    align: 'center',
                    title: '上架',
                    width: 80,
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 180
                },
                {
                    title: '操作',
                    align: 'left',
                    width: '180px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="albumView(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a> ');
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="openContent(\'' + row.id + '\')"><i class="fa fa-object-group"></i>内容</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="albumEdit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        //添加图片
        $('#btn-add').click(function (){
            var index = layer.open({
                title: '添加专辑',
                content: prefix + "/add.html?channelId=" + channelId,
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['80%','95%']
            });
        })
    });

    /* 状态显示 */
    function statusTools(row) {
        if (row.status === 1) {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="updateStatus(\'' + row.id + '\',\'' + 0 + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="updateStatus(\'' + row.id + '\',\'' + 1 + '\')"></i> ';
        }
    }

    //上架与下架
    function updateStatus(id, status) {
        table.set();
        var str = "";
        if (status > 0) {
            str = "确定执行上架操作"
        } else {
            str = "确定执行下架操作"
        }
        $.modal.confirm(str, function () {
            var data = {"id": id, "status": status};
            $.operate.submit(prefix + "/update/status.json", "post", "json", data);
        });
    }

    //详情
    function albumEdit(id) {
        var index = layer.open({
            title: '编辑专辑',
            content: prefix + '/edit.html?id='+id,
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['70%', '80%']
        });
    }

    //详情
    function albumView(id) {
        var index = layer.open({
            title: '专辑详情',
            content: prefix + '/view.html?id='+id,
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['70%', '80%']
        });
    }

    //打开管理窗口
    function openContent(id) {
        $.modal.openTab("内容管理", prefix+"/item/list.html?id=" + id);
    }
</script>
</body>
</html>